package test.lx.com.view_qualify;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2015/10/6.
 */
public class CheckView extends View {
    private Context context;
    int checkNum[]=null;
    Paint paint =new Paint();

    public CheckView(Context context) {
        super(context,null);
    }

    public CheckView(Context context, AttributeSet attrs) {
        super(context, attrs,0);
        this.context=context;
        //设置抗锯齿
        paint.setAntiAlias(true);
        paint.setTextSize(Config.TEXT_SIZE);
        paint.setStrokeWidth(3);



    }

    public CheckView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public CheckView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(Config.COLOR);
        final int height = getHeight();//获得CheckView控件的高度
        final int width = getWidth();//获得CheckView控件的宽度
        int dx = 40;
        for(int i = 0; i < 4; i ++){//绘制验证控件上的文本
            canvas.drawText("" + checkNum[i],  dx, CheckUtils.getPositon(height), paint);
            dx += width/ 5;
        }
        int [] line;
        for(int i = 0; i < Config.LINE_NUM; i ++){//划线
            line = CheckUtils.getLine(height, width);
            canvas.drawLine(line[0], line[1], line[2], line[3], paint);
        }

    }
    public void setCheckNum(int [] chenckNum) {//设置验证码
        checkNum = chenckNum;
    }
    public int[] getCheckNum() {//获得验证码
        return checkNum;
    }
    public void invaliChenkNum() {
        invalidate();
    }
}
